<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title></title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="../static/elderlyInfo/main/layui/css/layui.css" media="all">
<link rel="stylesheet" href="../static/elderlyInfo/main/css/thesame.css" media="all">
<link rel="stylesheet" href="../static/elderlyInfo/main/css/footer.css" media="all">
<link rel="stylesheet" href="../static/elderlyInfo/css/rightCon.css" media="all">
<link rel="stylesheet" href="../static/elderlyInfo/css/page.css" media="all">
<link rel="stylesheet" href="../static/elderlyInfo/css/popCss.css" media="all">
<style type="text/css">
	.layui-table-header input{ width: 250px; margin: 5px auto; }
</style>
</head>

<body class="layui-layout-body">
	<div class="layui-body">
		<div class="add-title pad25px">
			<span class="mr10px cursor" onclick="back()">
				<img src="../static/elderlyInfo/img/return_icon.png">
			</span>
			<span>新建角色</span>
		</div>
		<!-- 内容主体区域 -->
		<!-- <div class="layui-box-con layui-box-con-posi relative"> -->
			<!-- <div class="layui-left-con layui-left-label-con layui-left-con-bot pad12px">
				<div class="border-radius4 bgWhite box-shadows">
					<div class="new-add-box-scroll">
						<nav class="label-nav-con">
							<p class="f16px lh40px" style="padding-left: 33px;">全部</p> 
							<ul class="lh40px f14px">
								<li class="current">床位费</li>
								<li>护理费</li>
								<li>长护险补贴</li>
								<li>认知情况</li>
								<li>居家情况</li>
								<li>认知情况</li>
							</ul>
						</nav>
					</div>
				</div>
			</div> -->
			<!-- <div class="layui-right-con layui-right-label-con layui-right-con-bot"> -->
				<div class="new-add-box new-add-box-width bgWhite box-shadows border-radius4">
					<div class="add-box-scroll">
				<!-- <div class="border-radius4 bgWhite box-shadows">
					<div class="new-add-box-scroll"> -->
						<div class="mar25px">
							<div class="mb25px">
								<div class="new-add-title relative overflow mb15px"><span class="ml15px">基本信息</span></div>
								<div class="new-add-con new-add-form pb25px border-bot1px">
									<article class="new-add-left new-add-form-con">
										<ul class="overflow">
											<li>
												<p><label><em class="red">*</em>姓名：</label></p>
												<p><input type="text" id="userName" placeholder="请输入" class="layui-input"></p>
											</li>
											<li class="layui-form">
												<p><label>认知：</label></p> 
												<p>
													<span><input type="radio" name="cognitionStatus" checked="checked" value="0" title="否"></span>
													<span><input type="radio" name="cognitionStatus" value="1" title="是"></span>
												</p>
											</li>
											<li>
												<p><label><em class="red">*</em>民族 ：</label></p>
												<p>
													<select id="nation" class="form-select">
														<option value="">请选择</option>
														<option th:each="list:${pageData.nationList}" th:value="${list.labelCode}"  th:text="${list.labelName}"></option>
													</select>
												</p>
											</li>
											<li>
												<p><label><em class="red">*</em>户籍类型：</label></p>
												<p>
													<select id="householdRegister" class="form-select">
														<option value="">请选择</option>
														<option th:each="list:${pageData.householdRegisterList}" th:value="${list.labelCode}"  th:text="${list.labelName}">
														</option>
													</select>
												</p>
											</li>
											<li>
												<p><label><em class="red">*</em>身份证号：</label></p>
												<p><input id="userPid" th:value="${userPid}" onBlur="setAgeOfInput()" type="text" placeholder="请输入" class="layui-input"></p>
											</li> 
											<li>
												<p><label><em class="red">*</em>性别：</label></p>
												<p>
													<select id="userSex" class="form-select">
														<option value="">请选择</option>
														<option value="1">男</option>
														<option value="2">女</option>
													</select>
												</p>
											</li>
											<li>
												<p><label>年龄：</label></p>
												<p><input id="age" type="text" placeholder="请输入" class="layui-input" disabled=""></p>
											</li>
											<li>
												<p><label>文化程度：</label></p>
												<p>
													<select id="education" class="form-select"> 
														<option value="">请选择</option>
														<option th:each="list:${pageData.educationList}" th:value="${list.labelCode}"  th:text="${list.labelName}"></option>
													</select>
												</p>
											</li>
											<li>
												<p><label>籍贯：</label></p>
												<p><input id="nativePlace" type="text" placeholder="请输入" class="layui-input"></p>
											</li>
											<li class="width-two">
												<p><label><em class="red">*</em>家庭地址：</label></p>
												<p><input id="liveAddress" type="text" placeholder="请输入" class="layui-input"></p>
											</li>
											<li>
												<p><label><em class="red">*</em>社保类型：</label></p>
												<p>
													<select id="socialSecurityType" class="form-select">
														<option value="">请选择</option>
														<option th:each="list:${pageData.socialSecurityTypeList}" th:value="${list.labelCode}"  th:text="${list.labelName}"></option>
													</select> 
												</p>
											</li>
											<li>
												<p><label><em class="red">*</em>社保卡号：</label></p>
												<p><input id="socialSecurityCardNo" type="text" placeholder="请输入" class="layui-input"></p>
											</li>
											<li>
												<p><label>工作单位：</label></p>
												<p><input id="retireCompany" type="text" placeholder="请输入" class="layui-input"></p>
											</li>
											<li>
												<p><label>职业：</label></p>
												<p><input id="occupation" type="text" placeholder="请输入" class="layui-input"></p>
											</li>
										</ul>
									</article>
									<article class="new-add-right">
										<dl class="inline-block relative">
											<dt>
												<p class="filejs"><img src="../static/elderlyInfo/img/moren.png" id="imgPath" class="bock"></p>
												<!-- <input type="file" class="hidden file" /> -->
												<input type="file" id="file_input" class="hidden file" />
											</dt>
											<dd class="white lh30px textCenter">默认头像</dd>
										</dl>
									</article>
								</div>
							</div>
							<div class="mb25px">
								<div class="new-add-title relative overflow mb15px"><span class="ml15px">紧急联系人</span></div>
								<div class="pb20px border-bot1px">
									<!-- <div class="mt25px mb15px lh32px overflow add-btn-input">
										<p class="left cursor">
											<span class="white border-radius4 bgGreen inline-block pl15px pr15px"><img src="../static/elderlyInfo/img/button_add.png">添加</span>
										</p>
									</div> -->
									<div class="border1px border-radius4">
										<!-- <table class="layui-hide" id="test1" lay-filter="test"></table> -->
										<table class="layui-table layui-table-header">
											<thead>
												<tr>
													<th>姓名</th>
													<th><span class="red">*</span>手机号码</th>
												</tr>
											</thead>
											<tbody>
												<tr>
													<td><input type="text" id="contactName1" placeholder="请输入姓名" class="layui-input"></td>
													
													<td><input type="text" id="mobile1" placeholder="请输入手机号" class="layui-input"></td>
												</tr>
												<tr>
													<td><input type="text" id="contactName2" placeholder="请输入姓名" class="layui-input"></td>
													
													<td><input type="text" id="mobile2" placeholder="请输入手机号" class="layui-input"></td>
												</tr>
												
												<tr>
													<td><input type="text" id="contactName3" placeholder="请输入姓名" class="layui-input"></td>
													
													<td><input type="text" id="mobile3" placeholder="请输入手机号" class="layui-input"></td>
												</tr>
												<tr>
													<td><input type="text" id="contactName4" placeholder="请输入姓名" class="layui-input"></td>
													
													<td><input type="text" id="mobile4" placeholder="请输入手机号" class="layui-input"></td>
												</tr>
											</tbody>
										</table>
									</div>
								</div>
							</div>
							<div class="mb25px">
								<div class="new-add-title relative overflow mb15px"><span class="ml15px">养老院信息</span></div>
								<div class="new-add-con new-add-form pb25px border-bot1px">
									<article class="new-add-left new-add-form-con">
										<ul class="overflow">
											<li>
												<p><label><em class="red">*</em>入住时间：</label></p>
												<p><input type="text" id="startDate" placeholder="请选择" class="layui-input layui-time test-item1"></p>
											</li>
											<li>
												<p><label><em class="red">*</em>合同截止时间：</label></p>
												<p><input type="text" id="endDate" placeholder="请选择" class="layui-input layui-time test-item2"></p>
											</li>
											<li>
												<p><label><em class="red">*</em>入住保证金（元）：</label></p>
												<p><input type="text" id="inDeposit" onkeyup="changeNum(this);" placeholder="请输入" class="layui-input"></p>
											</li>
											<li>
												<p><label><em class="red">*</em>缴纳时间：</label></p>
												<p><input type="text" id="paymentDate" placeholder="请选择" class="layui-input layui-time test-item3"></p>
											</li>
											<li>
												<p><label><em class="red">*</em>楼苑 ：</label></p>
												<p>
													<select id="buildingNo" class="form-select"> 
														<option value="">请选择</option>
														<option th:each="list:${buildingList}" th:value="${list.buildingNo}"  th:text="${list.buildingName}"></option>
													</select>
												</p>
											</li> 
											<li>
												<p><label><em class="red">*</em>楼层 ：</label></p>
												<p>
													<select id="floorNo" class="form-select">
														<option value="">请选择</option>
														<!-- <option value="">大陆身份证</option>
														<option value="">大陆身份证</option> -->
													</select>
												</p>
											</li>
											<li>
												<p><label><em class="red">*</em>房间号 ：</label></p>
												<p>
													<select id="roomNo" class="form-select">
														<option value="">请选择</option>
														<!-- <option value="">大陆身份证</option>
														<option value="">大陆身份证</option> -->
													</select>
												</p>
											</li>
											<li>
												<p><label><em class="red">*</em>床位 ：</label></p>
												<p>
													<select id="bedNo" class="form-select">
														<option value="">请选择</option>
														<<!-- option value="">大陆身份证</option>
														<option value="">大陆身份证</option> -->
													</select>
												</p>
											</li>
											<li>
												<p><label><em class="red">*</em>床位费标准 ：</label></p>
												<p>
													<select id="bedFeeType" class="form-select">
														<option value="">请选择</option>
														<option th:each="list:${pageData.bedFeeTypeList}" th:value="${list.costNo}"  th:text="${list.costPrice}"></option>
													</select>
												</p>
											</li>
											<li> 
												<p><label><em class="red">*</em>护理等级 ：</label></p>
												<p>
													<select id="nursingCostNo" class="form-select">
														<option value="">请选择</option>
														<option th:each="list:${pageData.nursingCostList}" th:value="${list.costNo}"  th:text="${list.costName}"></option>
													</select>
												</p>
											</li>
											<li>
												<p><label><em class="red">*</em>护理评估生效时间：</label></p>
												<p><input type="text" id="nursingEffectDate" placeholder="请选择" class="layui-input layui-time test-item4"></p>
											</li>
											<li>
												<p><label><em class="red">*</em>护理人员：</label></p>
												<p>
													<input onclick="staffInfoLayerOpen()" id="staffName" readonly="readonly"  type="text" placeholder="请输入" class="layui-input">
													<input type="hidden" id="staffNo" value="" name="">>
													<span style="position: absolute; right: 30px; top: 0; height: 32px; padding: 0 10px;"><img src="../static/elderlyInfo/img/icon_hlry.png" alt=""></span>
												</p>
											</li>
											<li>
												<p><label><em class="red">*</em>评估等级 ：</label></p>
												<p>
													<select id="assessmentCostNo" class="form-select">
														<option value="">请选择</option>
														<option th:each="list:${pageData.assessmentCostList}" th:value="${list.costNo}"  th:text="${list.costName}"></option>
													</select>
												</p>
											</li>
											<li>
												<p><label><em class="red">*</em>评估有效期：</label></p>
												<p><input id="validDate" type="text" placeholder="请选择" class="layui-input layui-time test-item5"></p>
											</li>
											<li>
												<p><label><em class="red">*</em>收费情况（元）：</label></p>
												<p><input type="text" id="costFee" onkeyup="changeNum(this);" placeholder="请输入" class="layui-input"></p>
											</li>
										</ul>
									</article>
								</div>
							</div>
						</div>
					</div>
				</div>
			<!-- </div> -->
		<!-- </div> -->
	</div>
	<div class="layui-footer layui-footer-one">
		<div class="btn-con textCenter">
			<span class="btn-one cursor" onclick="back()">取&nbsp;消</span>
			<span class="btn-two cursor" onclick="confirmAdd()">提&nbsp;交</span>
		</div>
	</div>

	<div id="pop-con" style="display: none;">
		<div class="pop-up">
			<div>
				<div class="pop-title relative overflow mb15px">
					<span class="ml15px">护理员</span>
					<p class="right"><img src="../static/elderlyInfo/img/close_icon.png" class="block pop-close"><p>
				</div>
				<div class="border-top1px mt10px">
					<div class="overflow mt20px mb20px lh32px">
						<p class="left">共有<span id="totalNum" class="red"></span>条数据</p>
						<div class="add-mess-form-border right relative ml30px">
							<p><input id="searchStaffName" type="text" placeholder="请输入"></p>
							<span onclick="getStaffInfoList()"><img src="../static/elderlyInfo/img/icon_search.png"></span>
						</div>
					</div>
					<article class="pop-box">
						<div class="pop-box-scroll">
							<div class="border1px border-radius4">
								<table class="layui-hide" id="test2" lay-filter="test2"></table>
							</div>
						</div>
					</article>
				</div>
				<div class="btn-con btn-con-position textCenter mt20px">
					<span class="btn-one" onclick="cancelOfLayerOpen()">取&nbsp;消</span>
					<span class="btn-two" onclick="confirmOfLayerOpen()">提&nbsp;交</span>
				</div>
			</div>
		</div>
	</div>
<script src="../static/elderlyInfo/main/js/jquery-2.1.3.min.js"></script>
<script src="../static/elderlyInfo/main/layui/layui.js" charset="utf-8"></script>
<script>
	$(function(){

		layui.use(['element' , 'form'  , 'laydate' , 'layer'], function() {
			var laydate = layui.laydate;
			var start = laydate.render({
				elem: '.test-item1',
				done: function(value, date, endDate){
					//设置默认值-两年后
					var dateA=new Date(value);
					dateA.setFullYear(dateA.getFullYear()+2);
					var dd = (dateA.getDate()+"").length==1?"0"+dateA.getDate():dateA.getDate();
					var defaultEndDate  =  dateA.getFullYear() + '-' + (dateA.getMonth() + 1) + '-' + dd;
					$("#endDate").val(defaultEndDate);

					if(value!=""){
						date.month=date.month-1;
						end.config.min=date;
					}else{
						end.config.min=start.config.min;
					}
				}
			});
			var end = laydate.render({
				elem: '.test-item2',
				done : function(value, date, endDate){
					if(value!=""){
						date.month=date.month-1;
						end.config.min=date;
						start.config.max=end.config.min;
					}else{
						end.config.min=start.config.min;
					}
				}
			});


			laydate.render({
				elem: '.test-item3',
				trigger: 'click',
			});
			laydate.render({
				elem: '.test-item4',
				trigger: 'click',
			});
			laydate.render({
				elem: '.test-item5',
				trigger: 'click',
			});
		});

		//选中样式
		$('.label-nav-con li').click(function() {
			$(this).addClass('current').siblings().removeClass('current');
		})
		$(".filejs").click(function() {
			$(".file").click();
		})
		//上传图片
		document.getElementById("file_input").addEventListener('change', readFile, false);
			
		//初始化加载老人档案数据 
		loadUserInfo();

		//staffInfoLayerOpen();

		//楼苑--》楼层
		$("#buildingNo").change(function () {
           	getFloorOption();
        });

        //楼层--》房间号
		$("#floorNo").change(function () {
           	getRoomOption();
        });

        //房间号--》床位号
		$("#roomNo").change(function () {
           	getBedOption();
        });
	});


	function readFile() {
		var input = document.getElementById("file_input");
		var dataArr = []; // 储存所选图片的结果(文件名和base64数据)

        var fd = new FormData();
        var iLen = this.files.length;
        var index = 0;
        for (var i = 0; i < iLen; i++) {
            if (!input['value'].match(/.jpg|.gif|.png|.jpeg|.bmp/i)) {　　//判断上传文件格式
            	layer.msg('上传的图片格式不正确，请重新选择', {time: 3000});
     //        	layer.open({
			 	// 	content: '上传的图片格式不正确，请重新选择'
			 	// 	,skin: 'msg'
			 	// 	,time: 2 //2秒后自动关闭
			 	// });
                return ;
            }
            var reader = new FileReader();
            reader.index = i;
            //fd.append(i,this.files[i]);
            fd.append("file", this.files[i]);
            sendImage(fd);//传送图片
            reader.readAsDataURL(this.files[i]);  //转成base64
            reader.fileName = this.files[i].name;
			//var imageName2= 
			
			//console.log("====="+imageName2);
            reader.onload = function (e) {
                var imgMsg = {
                    name: this.fileName,//获取文件名
                    base64: this.result   //reader.readAsDataURL方法执行完后，base64数据储存在reader.result里
                }
                dataArr.push(imgMsg);
                $('#imgPath').attr('src', imgMsg.base64); //图片链接（base64）
            }

            
        }
    }

    function sendImage(fd) {
        $.ajax({
            url: '../img/uploadImage',
            type: 'post',
            data: fd,//JSON.stringify(submitArr),
            dataType: 'json',
            cache: false,
            processData: false,   //用FormData传fd时需有这两项     必要
            contentType: false,    //必要
            async: true,
            beforeSend:function(){
            	layer.load(2);
            },
            success: function (res) {
            	layer.closeAll();
                if (res.code == "0000") {
                	$('#imgPath').attr('value', res.msg); //图片链接（base64）
                	//$('#imgPath').attr('src', res.msg); //图片链接（base64）
                }else{
                	return layer.msg("图片上传失败，请重试", {time: 2000});
                }
            }
        });
    }


	//输入身份证号失去焦点 更改年龄
	function setAgeOfInput(){
		var userPid = $("#userPid").val();
		if (userPid.length==18) {
			var age = getAgeByIdCard(userPid);
			$("#age").val(age);
		}else{
			$("#age").val("");
		}
	}

	//初始化老人档案信息 如果身份证号存在
	function loadUserInfo(){
		var userPid = $("#userPid").val();
		if (isNull(userPid)) {
			return;
		}
		//通过身份证计算出年龄
		var age = getAgeByIdCard(userPid);
		$("#age").val(age);

		var formDate =
	        {
	        	userPid : userPid
	        };

		$.ajax({
            url: "../userInfo/getUserInfoByUserPid",
            type: "post",
            dataType: "json",
            data: formDate,
            async: false,
            success: function (res) {
                if (res.code == "200") {
                	// console.log(res);
                	var userInfo = res.data;
                	if (isNull(userInfo)) {
                		return;
                	}
                	$("#userName").val(userInfo.userName);//姓名
                	$("#userSex").val(userInfo.userSex);//性别
                	// $("#householdRegister").val(userInfo.householdRegister);//户籍
                	$("#nation").val(userInfo.nation);//民族
                	$("#liveAddress").val(userInfo.liveAddress);//居住地址
                	$("#socialSecurityType").val(userInfo.socialSecurityType);//社保类型
                	$("#socialSecurityCardNo").val(userInfo.socialSecurityCardNo);//社保卡号
                	$("#education").val(userInfo.degreeOfEducation);//文化程度
                	$("#retireCompany").val(userInfo.retireCompany);//退休单位
                	$("#occupation").val(userInfo.occupation);//职业

                	if (!isNull(userInfo.assessmentLevel) && !isNull(userInfo.assessmentValidDate)) {
                		// assessmentCostNo validDate
						$("#assessmentCostNo").val(userInfo.assessmentLevel);//评估等级
						$("#validDate").val(userInfo.assessmentValidDate);//有效时间
                	}

                	//认知情况
					if (!isNull(userInfo.cognitionStatus)) {
						$("input[name=cognitionStatus][value='"+userInfo.cognitionStatus+"']").prop('checked', true);
					}
					//头像图片
					if (!isNull(userInfo.imgPath)) {
						$('#imgPath').attr('value', userInfo.imgPath); 
			            $('#imgPath').attr('src', userInfo.imgPath); 
					}

					//*****主要联系人********
					if (!isNull(userInfo.userInfoContactList)) {
						for (var i = 0; i < userInfo.userInfoContactList.length; i++) {
							var userInfoContact = userInfo.userInfoContactList[i];
							initUserInfoContact(i+1,userInfoContact)
						}
					}
                } else {
                	
                }
            }
        });
	}


	//初始化联系人
	function initUserInfoContact(num,userInfoContact){
		$("#contactName"+num).val(userInfoContact.contactName);//联系人姓名
		$("#mobile"+num).val(userInfoContact.mobile);//手机号
		
	}



	//获取楼层信息
	function getFloorOption(){
		var buildingNo = $("#buildingNo").val();
		if (isNull(buildingNo)) {
			$("#floorNo").val("");
 			$("select[id='floorNo']").html("<option value=\"\">请选择</option>");
			$("#roomNo").val("");
			$("select[id='roomNo']").html("<option value=\"\">请选择</option>");
			$("#bedNo").val("");
			$("select[id='bedNo']").html("<option value=\"\">请选择</option>");
			return;
		}
		var optInit = "";
        var opt = "";
		var formDate =
	        {
	        	buildingNo : buildingNo
	        };
		$.ajax({
            url: "../elderlyInfo/getFloorByBuildingNo",
            type: "get",
            dataType: "json",
            data: formDate,
            async: false,
            success: function (res) {
                if (res.code == "200") {
                    optInit += "<option value=\"\">请选择</option>";
                    for (var i = 0; i < res.data.length; i++) {
                        opt += "<option value=" + res.data[i].floorNo + ">" + res.data[i].floorName + "</option>";
                    }
                    // 选择下拉菜单
                    var select = $("select[id='floorNo']");
                    // 拼接下拉菜单
                    if (!isNull(opt)) {
                        select.html(optInit + opt);
                    } else {
                        select.html(optInit);
                    }
                } else {
                	layer.msg("获取楼层信息失败，请稍后重试", {icon: 2,time:1500});
                }
            }
        });
	}


	//获取房间信息
	function getRoomOption(){
		var floorNo = $("#floorNo").val();
		if (isNull(floorNo)) {
			$("#roomNo").val("");
			$("select[id='roomNo']").html("<option value=\"\">请选择</option>");
			$("#bedNo").val("");
			$("select[id='bedNo']").html("<option value=\"\">请选择</option>");
			return;
		}
		var optInit = "";
        var opt = "";
		var formDate =
	        {
	        	floorNo : floorNo
	        };
		$.ajax({
            url: "../elderlyInfo/getRoomByFloorNo",
            type: "get",
            dataType: "json",
            data: formDate,
            async: false,
            success: function (res) {
                if (res.code == "200") {
                    optInit += "<option value=\"\">请选择</option>";
                    for (var i = 0; i < res.data.length; i++) {
                        opt += "<option value=" + res.data[i].roomNo + ">" + res.data[i].roomName + "</option>";
                    }
                    // 选择下拉菜单
                    var select = $("select[id='roomNo']");
                    // 拼接下拉菜单
                    if (!isNull(opt)) {
                        select.html(optInit + opt);
                    } else {
                        select.html(optInit);
                    }

                } else {
                	layer.msg("获取房间信息失败，请稍后重试", {icon: 2,time:1500});
                }
            }
        });
	}

	//获取床位信息
	function getBedOption(){
		var roomNo = $("#roomNo").val();
		if (isNull(roomNo)) {
			$("#bedNo").val("");
			$("select[id='bedNo']").html("<option value=\"\">请选择</option>");
			return;
		}
		var optInit = "";
        var opt = "";
		var formDate =
	        {
	        	roomNo : roomNo
	        };
		$.ajax({
            url: "../elderlyInfo/getBedByRoomNo",
            type: "get",
            dataType: "json",
            data: formDate,
            async: false,
            success: function (res) {
                if (res.code == "200") {
                    optInit += "<option value=\"\">请选择</option>";

                    for (var i = 0; i < res.data.length; i++) {
                        opt += "<option value=" + res.data[i].bedNo + ">" + res.data[i].bedName + "</option>";
                    }
                    // 选择下拉菜单
                    var select = $("select[id='bedNo']");
                    // 拼接下拉菜单
                    if (!isNull(opt)) {
                        select.html(optInit + opt);
                    } else {
                        select.html(optInit);
                    }

					// if (res.data.length==0) {
					// 	layer.msg("此房间号没有空置床位,请重新选择", {time: 1500});
					// }

                } else {
                	layer.msg("获取床位信息失败，请稍后重试", {icon: 2,time:1500});
                }
            }
        });
	}


	//获取护理员信息
	function getStaffInfoList(){
		//左侧菜单栏
		layui.use(['table'], function() {
			var table = layui.table;
			var searchStaffName = $("#searchStaffName").val();
		 	var formDate =
	        {
	        	staffName : searchStaffName
	        };

			//第一个实例
			table.render({
				elem: '#test2'//,url: '/demo/table/user/'
				,url:"../elderlyInfo/getYlStaffInfoList"
				,where:formDate
				,request: {
					 pageName: 'currentPage' //页码的参数名称，默认：page
					 ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
				}
				//,count: 10  //数据总数，从服务端得到
				//,data: listData
				,page: true //开启分页
				,limit:10 //每页显示的条数
				//,limits:[3,4,5]
				,groups: 3 //连续页码个数
				,parseData:function(res){
						return{
							"code":res.code,
							"data":res.data.data,
							"count":res.data.totalCount,
							"limit":res.data.pageSize,
						};
				}
				,cols: [
					[ 
						{
							type: 'radio',
						},
						{
							field: 'staffName',
							title: '姓名',
						}, {
							field: 'post',
							title: '岗位',
						}
					]
				]
				,done:function(res, curr, count){
				    $("#totalNum").text(count);

				    //监听事件
				    table.on('radio(test2)', function(obj){
						//查看obj结构 console.log(obj); console.log(obj.checked);  //是否选中，选中为true
						//选中行的数据  
						// console.log(obj.data);
						staffNo = obj.data.staffNo;
						staffName = obj.data.staffName;
					});
				}
			});
		});

	}

	
	//弹层的 取消 按钮
	var staffNo = "";
	var staffName ="";
	function cancelOfLayerOpen(){
		// staffNo ="";
		// staffName ="";
		$("#searchStaffName").val("");
		layer.closeAll();
	}

	//弹层的 提交 按钮
	function confirmOfLayerOpen(){
		//给input框赋值
		$("#staffName").val(staffName);
		$("#staffNo").val(staffNo);
		$("#searchStaffName").val("");
		layer.closeAll();
	}


	//护理员弹框
	function staffInfoLayerOpen(){
		layui.use(['element' , 'form' , 'table' , 'laydate' , 'layer'], function() {
			var layer = layui.layer;
			layer.open({
					type: 1,
					title: false, //不显示标题栏
					closeBtn: false,
					area: ['800px', '600px'],
					shade: 0.6,
					id: 'payCons', //设定一个id，防止重复弹出
					/*,btn: ['确认支付']*/
					btnAlign: 'c',
					moveType: 1, //拖拽模式，0或者1
					shadeClose: true, //设置允许点遮罩关闭
					content: $("div#pop-con"),
					success: function() {
						getStaffInfoList();
						//关闭弹层
						$(".pop-close").click(function() {
							layer.closeAll();
						});
					},
				
				});
		})
	}


	function back(){
		 window.history.back();
	}



	//确认保存
	function confirmAdd(){
		//==============基本信息=================================
		var userName = $("#userName").val();//姓名
		var cognitionStatus =$("input:radio[name='cognitionStatus']:checked").val();//认知
		var userSex = $("#userSex").val();//性别
		var nation = $("#nation").val();//民族
		var householdRegister = $("#householdRegister").val();//户籍类型
		var userPid = $("#userPid").val();//身份证号
		var age = $("#age").val();//年龄
		var education = $("#education").val();//文化程度
		var nativePlace = $("#nativePlace").val();//籍贯
		var liveAddress = $("#liveAddress").val();//家庭地址
		var socialSecurityType = $("#socialSecurityType").val();//社保类型
		var socialSecurityCardNo = $("#socialSecurityCardNo").val();//社保卡号
		var retireCompany = $("#retireCompany").val();//工作单位
		var occupation = $("#occupation").val();//职业
		var imgPath = $("#imgPath").attr("value"); //头像

		if (isNull(userName)) {
			layer.msg("姓名不能为空", {time: 2000});
			return;
		}else if (userName.length>14) {
			layer.msg("姓名过长", {time: 2000});
			return;
		}

		if (isNull(nation)) {
			layer.msg("民族不能为空", {time: 2000});
			return;
		}
		if (isNull(householdRegister)) {
			layer.msg("户籍类型不能为空", {time: 2000});
			return;
		}
		if (isNull(userPid)) {
			layer.msg("身份证号不能为空", {time: 2000});
			return;
		}else if (userPid.length>18) {
			layer.msg("身份证号过长", {time: 2000});
			return;
		}else if(!checkUserPid(userPid)){
			layer.msg('请填写正确的身份证', {time: 2000});
			return;
		}



		if (isNull(userSex)) {
			layer.msg("性别不能为空", {time: 2000});
			return;
		}
		if (!isNull(nativePlace)) {
			if (nativePlace.length>20) {
				layer.msg("籍贯过长", {time: 2000});
				return;
			}
		}
		if (isNull(liveAddress)) {
			layer.msg("家庭地址不能为空", {time: 2000});
			return;
		}else if(liveAddress.length>50){
			layer.msg("家庭地址过长", {time: 2000});
			return;
		}
		if (isNull(socialSecurityType)) {
			layer.msg("社保类型不能为空", {time: 2000});
			return;
		}

		if (isNull(socialSecurityCardNo)) {
			layer.msg("社保卡号不能为空", {time: 2000});
			return;
		}else if(socialSecurityCardNo.length>20){
			layer.msg("社保卡号过长", {time: 2000});
			return;
		}
		if (!isNull(retireCompany)) {
			if (retireCompany.length>20) {
				layer.msg("工作单位过长", {time: 2000});
				return;
			}
		}
		if (!isNull(occupation)) {
			if (occupation.length>20) {
				layer.msg("职业过长", {time: 2000});
				return;
			}
		}


		//========================紧急联系人=======================
		//联系人   1号
		var contactName1 =$("#contactName1").val();
		var mobile1 =$("#mobile1").val();
		//联系人   2号
		var contactName2 =$("#contactName2").val();
		var mobile2 =$("#mobile2").val();
		//联系人   3号
		var contactName3 =$("#contactName3").val();
		var mobile3 =$("#mobile3").val();
		//联系人   4号
		var contactName4 =$("#contactName4").val();
		var mobile4 =$("#mobile4").val();
		//紧急联系人必填一条
		if (isNull(contactName1) && isNull(mobile1) 
			&& isNull(contactName2) && isNull(mobile2)
			 && isNull(contactName3) && isNull(mobile3) 
			 && isNull(contactName4) && isNull(mobile4) ) {
			layer.msg("请至少输入一个紧急联系人", {time: 2000});
			return ;
		}
		var a1 = checkContactPeople("一",contactName1,mobile1);
		var a2 = checkContactPeople("一",contactName2,mobile2);
		var a3 = checkContactPeople("一",contactName3,mobile3);
		var a4 = checkContactPeople("一",contactName4,mobile4);
		if (!a1 || !a2 || !a3 || !a4 ) {
			return;
		}


		//===================养老院信息==================================
		var startDate = $("#startDate").val();//入住时间
		var endDate = $("#endDate").val();//合同截止时间
		var inDeposit = $("#inDeposit").val();//入住保证金（元）
		var paymentDate = $("#paymentDate").val();//缴纳时间
		var buildingNo = $("#buildingNo").val();//楼苑
		var floorNo = $("#floorNo").val();//楼层号
		var roomNo = $("#roomNo").val();//房间号
		var bedNo = $("#bedNo").val();//床位
		var bedFeeType = $("#bedFeeType").val();//床位费标准
		var nursingCostNo = $("#nursingCostNo").val();//护理等级
		var nursingEffectDate = $("#nursingEffectDate").val();//护理评估生效时间
		var staffNo = $("#staffNo").val();//护理人员
		var assessmentCostNo = $("#assessmentCostNo").val();//评估等级
		var validDate = $("#validDate").val();//评估有效期
		var costFee = $("#costFee").val();//收费情况（元）


		if (isNull(startDate)) {
			layer.msg("入住时间不能为空", {time: 2000});
			return;
		}

		if (isNull(endDate)) {
			layer.msg("合同截止时间不能为空", {time: 2000});
			return;
		}

		if (isNull(inDeposit)) {
			layer.msg("入住保证金不能为空", {time: 2000});
			return;
		}

		if (isNull(paymentDate)) {
			layer.msg("缴纳时间不能为空", {time: 2000});
			return;
		}

		if (isNull(buildingNo)) {
			layer.msg("楼苑不能为空", {time: 2000});
			return;
		}

		if (isNull(floorNo)) {
			layer.msg("楼层号不能为空", {time: 2000});
			return;
		}
		if (isNull(roomNo)) {
			layer.msg("房间号不能为空", {time: 2000});
			return;
		}
		if (isNull(bedNo)) {
			layer.msg("床位不能为空", {time: 2000});
			return;
		}
		if (isNull(bedFeeType)) {
			layer.msg("床位费标准不能为空", {time: 2000});
			return;
		}
		if (isNull(nursingCostNo)) {
			layer.msg("护理等级不能为空", {time: 2000});
			return;
		}
		if (isNull(nursingEffectDate)) {
			layer.msg("护理评估生效时间不能为空", {time: 2000});
			return;
		}
		if (isNull(staffNo)) {
			layer.msg("护理人员不能为空", {time: 2000});
			return;
		}
		if (isNull(assessmentCostNo)) {
			layer.msg("评估等级不能为空", {time: 2000});
			return;
		}
		if (isNull(validDate)) {
			layer.msg("评估有效期不能为空", {time: 2000});
			return;
		}
		if (isNull(costFee)) {
			layer.msg("收费情况不能为空", {time: 2000});
			return;
		}



		//============================整理数据=========================================
		//获取联系人 list
		var userInfoContactList = [];
		if (!isNull(mobile1)) {
			var userInfoContact1 = getUserInfoContact(contactName1,mobile1);
			userInfoContactList.push(userInfoContact1);
		}
		if (!isNull(mobile2) ) {
			var userInfoContact2 = getUserInfoContact(contactName2,mobile2);
			userInfoContactList.push(userInfoContact2);
		}
		if (!isNull(mobile3) ) {
			var userInfoContact3 = getUserInfoContact(contactName3,mobile3);
			userInfoContactList.push(userInfoContact3);
		}
		if (!isNull(mobile4) ) {
			var userInfoContact4 = getUserInfoContact(contactName4,mobile4);
			userInfoContactList.push(userInfoContact4);
		}

		console.log("userInfoContactList="+userInfoContactList);


		//获得合同
		var ylContractInfo = getYlContractInfo(startDate,endDate);
		//护理等级记录表
		var ylNursingRecord = getYlNursingRecord(nursingCostNo,nursingEffectDate,staffNo);
		//长护险评估记录表
		var ylAssessmentRecord = getYlAssessmentRecord(assessmentCostNo,validDate);
		//床位记录
		var ylBedRecord = getYlBedRecord(buildingNo,floorNo,roomNo,bedNo,bedFeeType);


		var formDate =
	        {
	        	//=====基本信息=========
	        	userName : userName,
	        	cognitionStatus : cognitionStatus,
	        	userSex : userSex,
	        	nation : nation,
	        	householdRegister : householdRegister,
	        	userPid : userPid,
	        	age : age,
	        	education : education,
	        	nativePlace : nativePlace,
	        	liveAddress : liveAddress,
	        	socialSecurityType : socialSecurityType,
	        	socialSecurityCardNo : socialSecurityCardNo,
	        	retireCompany : retireCompany,
	        	occupation : occupation,
	        	imgPath : imgPath,
	        	userInfoContactList : userInfoContactList,//紧急联系人
	        	//======养老院信息========
	        	inDeposit : inDeposit,
	        	paymentDate : paymentDate,
	        	costFee : costFee,
	        	ylContractInfo : ylContractInfo, //入驻合同
	        	ylNursingRecord : ylNursingRecord, //护理等级记录表
	        	ylAssessmentRecord : ylAssessmentRecord, //长护险评估记录表
	        	ylBedRecord : ylBedRecord, //床位记录
	        };

	    $.ajax({
			url: "../elderlyInfo/saveYlElderlyInfo",
			type: "post",
			contentType:"application/json;charset=utf-8",
			data: JSON.stringify(formDate),
			success: function (data) {
				console.log(data);
				if (data.code == "200") {
					layer.msg('保存成功', {icon: 1,time:1500},function(){
						window.location.href="../elderlyInfo/jumpElderlyInfoList";
					});
				} else {
					layer.msg(data.msg, {icon: 2});
				}
			}
		});

	}


	//获取联系人 对象
	function getUserInfoContact(contactName,mobile){
		return {"contactName":contactName,"mobile":mobile};
	}
	//获得合同 对象
	function getYlContractInfo(startDate,endDate){
		return {"startDate":startDate,"endDate":endDate};
	}
	//获得护理等级记录表
	function getYlNursingRecord(nursingCostNo,nursingEffectDate,staffNo){
		return {"costNo":nursingCostNo,"effectDate":nursingEffectDate,"staffNo":staffNo};
	}
	//获得长护险评估记录表
	function getYlAssessmentRecord(assessmentCostNo,validDate){
		return {"costNo":assessmentCostNo,"validDate":validDate};
	}
	//获得床位记录
	function getYlBedRecord(buildingNo,floorNo,roomNo,bedNo,bedFeeType){
		return {"buildingNo":buildingNo,"floorNo":floorNo,"roomNo":roomNo,"bedNo":bedNo,"bedFeeType":bedFeeType};
	}


	//联系人 姓名可以为空 联系电话不能为空
	function checkContactPeople(contactNum,name,mobile){
		if (!isNull(name)) {
			if (isNull(mobile)) {
				layer.msg("第"+contactNum+"联系人,"+"请输入联系电话", {time: 2000});
				return false;
			}else{
				if (!isPhoneNumber(mobile)) {
					layer.msg("第"+contactNum+"联系人,"+"手机号输入错误", {time: 2000});
					return false;
				}
			}
		}
		return true;
	}





	//通过身份证计算年龄
	function getAgeByIdCard(UUserCard) {
    	//获取年龄
	    var myDate = new Date();
	    var month = myDate.getMonth() + 1;
	    var day = myDate.getDate();
	    var age = myDate.getFullYear() - UUserCard.substring(6, 10) - 1;
	    if (UUserCard.substring(10, 12) < month || UUserCard.substring(10, 12) == month && UUserCard.substring(12, 14) <= day) {
	        age++;
	    }
	    return age;
	}

	function changeNum(obj) {
	    //如果用户第一位输入的是小数点，则重置输入框内容
	    if (obj.value != '' && obj.value.substr(0, 1) == '.') {
	        obj.value = "";
	    }
	    //粘贴不生效
	    obj.value = obj.value.replace(/^0*(0\.|[1-9])/, '$1'); 
	    //清除“数字”和“.”以外的字符
	    obj.value = obj.value.replace(/[^\d.]/g, "");  
	    //只保留第一个. 清除多余的
	    obj.value = obj.value.replace(/\.{2,}/g, ".");  
	    obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
	    //只能输入两个小数
	    obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); 
	    if (obj.value.indexOf(".") < 0 && obj.value != "") {
	        //以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
	        if (obj.value.substr(0, 1) == '0' && obj.value.length == 2) {
	            obj.value = obj.value.substr(1, obj.value.length);
	        }
	    }
	}

	function isNull(value) {
		return value == null || value === "" || value === undefined;
	}

	/**判断是否是手机号**/
	function isPhoneNumber(tel) {
	    var reg =/^0?1[3|4|5|6|7|8][0-9]\d{8}$/;
	    return reg.test(tel);
	}

	//检查身份证号码是否符合规范，包括长度，类型
	function checkUserPid(card)
	{
	    //身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X
	    var reg = /(^\d{15}$)|(^\d{17}(\d|X|x)$)/;
	    if(reg.test(card) === false)
	    {
	        return false;
	    }
	    return true;
	};
	

</script>
</body>

</html>
